package com.example.test_witns.ui.devices;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProvider;

import com.example.test_witns.ChatActivity;
import com.example.test_witns.R;
import com.example.test_witns.TempHumiActivity;
import com.example.test_witns.databinding.FragmentDevicesBinding;

public class DevicesFragment extends Fragment {

    private FragmentDevicesBinding binding;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        DevicesViewModel devicesViewModel =
                new ViewModelProvider(this).get(DevicesViewModel.class);

        binding = FragmentDevicesBinding.inflate(inflater, container, false);
        View root = binding.getRoot();

        Window window = getActivity().getWindow();
        window.setStatusBarColor(Color.parseColor("#eeeeee"));

        Context context = getContext();

        ConstraintLayout tempHumiSensor = root.findViewById(R.id.tempHumiSensor);
        tempHumiSensor.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent TempHumiActivityintent = new Intent(getContext(), TempHumiActivity.class);
                startActivity(TempHumiActivityintent);
            }
        });

        ConstraintLayout constraintLayout = root.findViewById(R.id.constraintLayout_device1);
        constraintLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Fragment fragment = getChildFragmentManager().findFragmentById(R.id.fragment_chat);
                if(fragment != null){
                    FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
                    /*?*/

                }else{
                    Context context1 = getContext();
                    Intent ChatNavigationView = new Intent(context1, ChatActivity.class);
                    startActivity(ChatNavigationView);
                }
            }
        });

        TextView textView = root.findViewById(R.id.text_send);
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Fragment fragment = getChildFragmentManager().findFragmentById(R.id.fragment_chat);
                if(fragment != null){
                    FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
                    /*?*/

                }else{
                    Context context1 = getContext();
                    Intent ChatNavigationView = new Intent(context1, ChatActivity.class);
                    startActivity(ChatNavigationView);
                }
            }
        });

        return root;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }
}